package com.study.spring.kafka;

import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.ProducerRecord;
import org.apache.kafka.clients.producer.RecordMetadata;
import org.apache.kafka.common.serialization.StringSerializer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Properties;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;

/**
 * TODO
 *
 * @author: zhang
 * @version: 3.0
 * @date: 2019-07-01 23:11:44
 * @since 1.8
 **/
public class ProduceTest {


    private static final Logger LOGGER = LoggerFactory.getLogger(ProduceTest.class);

    public static void main(String[] args) throws ExecutionException, InterruptedException {


        Properties props = new Properties();
        props.put("bootstrap.servers", "192.168.15.128:9092");
        props.put("acks", "all");
        props.put("retries", 0);
        props.put("batch.size", 1024);
        props.put("key.serializer", StringSerializer.class.getName());
        props.put("value.serializer", StringSerializer.class.getName());
        KafkaProducer<String, String> producer = new KafkaProducer<>(props);

        for (int i = 100; i < 1000000000; i++) {
            Future<RecordMetadata> future = producer.send(new ProducerRecord<String, String>("visit", "zhangyi" + i, "lihuan" + i));
            RecordMetadata recordMetadata = future.get();
            producer.flush();
            System.out.println(recordMetadata);
//            Thread.sleep(1000L);
        }
        producer.close();
    }
}
